package  
{
	import flash.text.TextField;
	/**
	 * ...
	 * @author patsup
	 */
	public class AchievementButton extends MenuButton 
	{
		private const A_BTN_COLOR:int = 0x0080FF;
		private const A_BTN_WIDTH:int = 120;
		private const A_BTN_HEIGHT:int = 40;
		
		private var mainRef:Main;
		public var achievementsReceived:Vector.<AchievementObject>;	//list of achievements awarded/completed
		public var achievements:Achievements;
		private var achText:TextField;
		
		public var last3Ach:Vector.<int>; //a list of the last three achievements recieved
		
		public function AchievementButton(mainRef:Main, xCoord:int, yCoord:int, inputFunc:Function) 
		{
			this.mainRef = mainRef;
			var imgData:ImageData = new ImageData(xCoord, yCoord, "Achievements", A_BTN_COLOR, A_BTN_WIDTH, A_BTN_HEIGHT);
			
			
			achievements = mainRef.GetGameRef().GetSS().GetAchievements();
			achievementsReceived = achievements.GetAchievementsReceived(); //yeah... i know...
			
			last3Ach = new Vector.<int>;
			
			achText = new TextField();
			addChild(achText);
			
			super(imgData, inputFunc);
		}
		
		//Refresh()
		//Initializes/refreshes the image of the btn
		//at start, removes all its children (even its name textfield) so it can correctly add the correct achiev children afterwards
		public function Refresh(ref:PreRoundMenuScreen):void
		{
			achievements.UpdateReceivedAppearance();
			var i:int;
			var _aLen:int = achievementsReceived.length;
			
			for (i = numChildren; i > 2; i = numChildren)	//don't remove 2 textlabels
			{
				removeChild(getChildAt(i-1));
			}
			
			
			var counter:int = 1;
			for (i = _aLen - 1; (i >= 0) && (i >= (_aLen - 5)) ; i--)	//only displays the last 5 achievements received
			{
				addChild(achievementsReceived[i]);
				
				
				
				//last3Ach.push(achievements.achRcvdIdx[i]);
				//counter++;
				
			}
			
			//textfield to display how many achievements received of total
			
			ref.ach_txt.text = "(" + achievementsReceived.length + "/" + achievements.GetAchievementList().length + ")";
			
			//achText.text = "( " + achievementsReceived.length + " / " + achievements.GetAchievementList().length + " )";
			achText.x = 30;
			achText.y = 22;
			
			
		}
		
	}

}